#ifndef NODE_H
#define NODE_H
#include "../manager/game.h"
#include <vector>
#include <string>
#include "enum.h"

class node {
    protected:
        nodeType type_ = nodeType::NODE_UNKNOWN;
        game& game_ = game::instance();
        std::vector<node*> children_;
        std::vector<node*> to_add;
        bool is_active_ = true;
        bool need_remove_ = false;
    public:
        std::string name_;
        node() = default;
        virtual ~node() = default;
        virtual void init(){};
        virtual void clean();
        virtual void render();
        virtual void update(float dt);
        virtual bool handleEvents(SDL_Event& event);
        void safeAddChild(node* child){
            to_add.push_back(child);
        }
        virtual void addChild(node* child){
            //SDL_Log("node %s addChild",child->name_.c_str());
            children_.push_back(child);
        }
        virtual void removeChild(node* child){
            children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
        }
        nodeType getType() const { return type_; }
        void setType(nodeType type) { type_ = type; }
        void setActive(bool active) { is_active_ = active; }
        bool isActive() const { return is_active_; }
        void setNeedRemove(bool need) { need_remove_ = need; }
        bool getNeedRemove() const { return need_remove_; }
        std::vector<node*>& getChildren() { return children_; }
};

#endif